#include "event/loop.hpp"

#include <chrono>
#include <iostream>
#include <thread>

using namespace std;
using namespace std::literals;
using namespace ibox;

int main() {
    auto loop = event::Loop();

    int count = 10;
    std::function<void()> func;
    func = [&] {
        while (count > 0) {
            count--;
            std::this_thread::sleep_for(100ms);
            cout << "count: " << count << '\n';
        };
    };

    event::TimerEvent tick_timer{loop.ptr(), 1s, event::Event::Mode::Forever};
    int i = 0;
    tick_timer.set_callback([&] { cout << "tick " << i++ << " ...\n"; });
    tick_timer.enable();

    loop.submit(func);
    loop.stop(5s);

    cout << "loop running ...\n";
    loop.run();
}
